var e = require("../../../../@babel/runtime/helpers/objectSpread2"),
  t = require("../../../../@babel/runtime/helpers/slicedToArray"),
  r = require("../../../../@babel/runtime/helpers/regeneratorRuntime"),
  a = require("../../../../@babel/runtime/helpers/asyncToGenerator"),
  n = require("../../../../utils/index"),
  s = n.helper.listOperate,
  i = n.tools.common.getHeaderHeight;
Component({
  componentPage: {
    onPullDownRefresh: function () {
      this.onRefresh(1).finally((function () {
        wx.stopPullDownRefresh()
      }))
    },
    onReachBottom: function () {
      this.isTabRefresh || this.data.hasMore || this.data.noData || this.onRefresh(this.page + 1)
    }
  },
  properties: {},
  data: {
    firstLoaded: !1,
    calcHeight: "0px",
    list: [],
    loading: !1,
    noData: !1,
    hasMore: !1
  },
  methods: {
    setRefresh: function (e) {
      var t = this;
      return a(r().mark((function a() {
        return r().wrap((function (r) {
          for (;;) switch (r.prev = r.next) {
            case 0:
              t.isTabRefresh = e;
            case 1:
            case "end":
              return r.stop()
          }
        }), a)
      })))()
    },
    setParams: function (e) {
      var t = this;
      return a(r().mark((function a() {
        return r().wrap((function (r) {
          for (;;) switch (r.prev = r.next) {
            case 0:
              t.params = e;
            case 1:
            case "end":
              return r.stop()
          }
        }), a)
      })))()
    },
    onRefresh: function () {
      var n = arguments,
        i = this;
      return a(r().mark((function a() {
        var o, u, c, h, l, f, p, d, g;
        return r().wrap((function (r) {
          for (;;) switch (r.prev = r.next) {
            case 0:
              return o = n.length > 0 && void 0 !== n[0] ? n[0] : 1, i.page = o || 1, 1 !== o && i.setData({
                  loading: !0
                }), r.prev = 2, u = e({
                  page: i.page,
                  page_size: 15,
                  source: "XCX"
                }, i.params), r.next = 6, u.pageNum = u.page,
                u.pageSize = u.page_size, u.userLatitude = u.latitude ? u.latitude : "", u.userLongitude = u.longitude ? u.longitude : "", u.type ? u.modelId = u.type : "", u.driverTypeId = u.type ? u.type : '', u.hits = u.pattern == 1 ? u.pattern : "", u.status = 3, u.cityId = u.addr, u.description = u.keywords ? u.keywords : "", $.request[u.mode == 1 ? "GET/business/seek/rent/pageList" : u.mode == 2 ? "GET/business/for/rent/pageList" : "GET/business/recruit/worker/pageList"](u);
            case 6:
              if (c = r.sent, h = t(c, 1), l = h[0], l.data.data.map(
                  item => {
                    item.title = item.description;
                    item.mode = u.mode;
                    item.time = item.createTime
                    item.timestamp = Date.parse(item.time) / 1000
                    if (item.coverImageUrlList) {
                      if (item.coverImageUrlList.length > 0) {
                        item.cover = item.coverImageUrlList[0]
                      }
                    }
                    item.class = [{
                      name: item.modelName,
                      value: item.modelName
                    }]
                    item.labels = {
                      address: {
                        name: "设备所在地",
                        value: item.provinceText + item.cityText + item.place
                      }
                    }
                    if (item.mfg) {
                      item.labels.manufacture_date = {
                        name: "出厂日期",
                        value: item.mfg
                      }
                    }
                    if (item.rent_price) {
                      item.labels.rent_price = {
                        name: "租赁价格",
                        value: item.rent ? `￥${item.rent?item.rent:0}元/月` : "￥-元/月"
                      }
                    }
                    if (item.number) {
                      item.labels.wanted_num = {
                        name: "数量",
                        value: item.number + "台"
                      }
                    }
                    if (item.worked_hour) {
                      item.labels.worked_hour = {
                        name: "租赁时间",
                        value: item.worked_hour + "小时"
                      }
                    }
                    if (item.leaseTerm) {
                      item.labels.rent_days = {
                        name: "租赁时间",
                        value: item.leaseTerm
                      }
                    }
                    if (item.factoryYears) {
                      item.labels.manufacture_limit = {
                        name: "出厂年限",
                        value: item.factoryYears + '年以内'
                      }
                    }
                  }
                ), f = l.data.data, p = s.getHistoryList(f), 1 !== o || 0 !== p.length) {
                r.next = 13;
                break
              }
              return r.abrupt("return", void i.setData({
                noData: !0,
                list: []
              }));
            case 13:
              if (p.length < 15 ? i.setData({
                  hasMore: !0
                }) : i.setData({
                  hasMore: !1
                }), 1 !== o) {
                r.next = 15;
                break
              }
              return r.abrupt("return", void i.setData({
                list: p,
                noData: !1
              }));
            case 15:
              d = i.data.list.length, g = p.reduce((function (e, t, r) {
                return e["list[".concat(r + d, "]")] = t, e
              }), {
                noData: !1
              }), i.setData(g);
            case 17:
              return r.prev = 17, i.setData({
                loading: !1
              }), !i.data.firstLoaded && setTimeout((function () {
                return i.setData({
                  firstLoaded: !0
                })
              }), 150), r.finish(17);
            case 20:
            case "end":
              return r.stop()
          }
        }), a, null, [
          [2, , 17, 20]
        ])
      })))()
    }
  },
  lifetimes: {
    ready: function () {
      var e = "calc(".concat(i("14rpx"), " + 170rpx)");
      this.setData({
        calcHeight: e
      })
    }
  },
  pageLifetimes: {
    show: function () {
      var e = this;
      return a(r().mark((function t() {
        var a;
        return r().wrap((function (t) {
          for (;;) switch (t.prev = t.next) {
            case 0:
              a = s.getHistoryList(e.data.list), e.setData({
                list: a
              });
            case 2:
            case "end":
              return t.stop()
          }
        }), t)
      })))()
    }
  }
});